<?php View::render('admin/layouts/meta');?>
<style>
    .j-u-del1{position:absolute;right:-0.6rem;top:-0.6rem;font-size:1.2rem;color:#dd514c;margin-top: 8px;}
    .j-u-del1:hover{text-decoration: none;color:#dd514c;}
</style>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.css" />
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>话题名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<?php echo $info ? $info['name'] : ''; ?>" placeholder="" name="name">
            </div>
        </div>

        <?php if (!$info) {
            ?>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">所属项目：</label>
                <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
				<select class="select" size="1" name="project_id">
                    <option value="">根分类</option>
                    <?php if ($categoryList) {
                        foreach ($categoryList as $category) {?>
                            <option value="<?php echo $category['id']; ?>" >
                        <?php echo $category['name']; ?>
                    </option>
                    <?php if ($category['child']) {foreach ($category['child'] as $item) {?>
                                <option value="<?php echo $item['id']; ?>">
                        <?php echo '|----' . $item['name']; ?>
                     </option>
                     <?php if ($item['child']) {foreach ($item['child'] as $cell) {?>
                                    <option value="<?php echo $cell['id']; ?>">
                        <?php echo '|--------' . $cell['name']; ?>
                     </option>
                                <?php }}}}?>
                        <?php }}?>
				</select>
				</span>
                </div>
            </div>
        <?php } else {
            ?>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">所属项目：</label>
                <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                <select class="select" size="1" name="project_id">
                    <option value="">根分类</option>
                    <?php if ($categoryList) {
                        foreach ($categoryList as $category) {?>
                            <option value="<?php echo $category['id']; ?>"  <?php if ($category['id']==$info["project_id"]) {echo 'selected="selected"';}?>>
                        <?php echo $category['name']; ?>
                    </option>
                    <?php if ($category['child']) {foreach ($category['child'] as $item) {?>
                                <option value="<?php echo $item['id']; ?>" <?php if ($item['id']==$info["project_id"]) {echo 'selected="selected"';}?>>
                        <?php echo '|----' . $item['name']; ?>
                     </option>
                     <?php if ($item['child']) {foreach ($item['child'] as $cell) {?>
                                    <option value="<?php echo $cell['id']; ?>"  <?php if (in_array($cell['categoryId'], $relate)) {echo 'selected="selected"';}?>>
                        <?php echo '|--------' . $cell['name']; ?>
                     </option>
                                <?php }}}}?>
                        <?php }}?>
                </select>
                </span>
                </div>
            </div>
        <?php }?>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>话题图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="clearfix">
                    <div class="">
                        <a id="j-upload">上传图片</a>
                    </div>
                    <div id="j-file" class="am-margin-top am-cf">
                        <?php if ($info && $info['images']) {?>
                            <div class="f-l mr-10 j-u-box">
                                <a href="javascirpt:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>
                                <input type="hidden" name="image" value="<?php echo $info['images']; ?>" />
                                <a href="javascript:;"><img class="thumbnail1" src="<?php echo $info['images']; ?>"  style="width:100px;height:100px" /></a>
                            </div>
                        <?php }?>
                    </div>
                </div>
                <span>图片大小:320px*640px</span>
            </div>
        </div>
<!--        <div class="row cl">-->
<!--            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片地址：</label>-->
<!--            <div class="formControls col-xs-8 col-sm-9">-->
<!--                <input type="text" class="input-text" value="--><?php //echo $info ? $info['images'] : ''; ?><!--" placeholder="" name="image">-->
<!--            </div>-->
<!--        </div>-->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>时间说明：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<?php echo $info ? $info['time'] : ''; ?>" placeholder="2019.12.31   9:00am - 3:00pm" name="project_time">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>话题详情：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea class="input-text" style="width:100%;height:150px"  placeholder="" name="content"><?php echo $info ? $info['content'] : ''; ?></textarea>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="discuss_id" value="<?php echo $info ? $info['id'] : 0; ?>" />
                <input class="btn btn-primary radius" type="button" id="j_submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
</body>
<?php View::render('admin/layouts/footer');?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.config.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.all.min.js?v=123"> </script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.min.js"></script>
<script type="text/javascript">
    $(function(){
        formData = {}
        $('#j_submit').click(function(){
            var $btn = $(this);
            $btn.button('loading');
            $.post('<?php echo Router::getBaseUrl(); ?>/admin_topic/edit', $('form').serialize(), function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1,
                        skin: 'u-msg',
                        time: 1800,
                    }, function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                    $btn.button('reset');
                    return true;
                }
                layer.msg(result.msg, {
                    icon: 0,
                    skin: 'u-msg',
                    time: 3000,
                }, function () {

                });
                $btn.button('reset');
            }, 'json');
            return;
        });
        var max_file = 1000, $list = $('#j-file');
        var uploader = WebUploader.create({
            fileVal: 'file',
            auto:true,
            swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
            server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
            pick: '#j-upload',
            // formData:formData,
            resize: true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            }
        });
        uploader.on('beforeFileQueued', function(file){
            addImgThumb(file);
        });
        // 生产图片预览
        function addImgThumb(file){
            uploader.makeThumb(file, function(error, ret){
                if(!error){
                    img = '<img alt="" src="' + ret + '" />';
                    $list.append(img);
                }else{
                    console.log('making img error');
                }
            },1,1);
        }
        uploader.on( 'uploadError', function( file ) {
            layer.msg('文件上传出错', {
                icon: 0,
                skin: 'u-msg',
                time: 3000,
            });
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            var img=response.url;
            var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="image" value="'+img+'" />\
                    <img class="thumbnail1" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
            $list.html(tpl);
            $('.j-u-del').on('click', function(){
                $(this).parent('div').remove();
            });
        });


        $('.j-u-del').on('click', function(){
            $(this).parent('div').remove();
        });


        var ue = UE.getEditor('editor');
    });

</script>
<script>
    // $(function(){
    //     $('.j-u-del1').on('click', function(){
    //         alert(111111);
    //     });
    // })
    function delattributes(obj,id) {
        if(id == 0){
            $(obj).parent().remove();
        }else{
            $.post('<?php echo Router::getBaseUrl(); ?>/admin_goods/deleteSpecification',{id: id}, function (result) {
                if (result.status == 200) {
                    $(obj).parent().remove();
                    layer.msg(result.msg, {
                        icon: 1,
                        skin: 'u-msg',
                        time: 1800,
                    }, function(){

                    });
                }
                layer.msg(result.msg, {
                    icon: 0,
                    skin: 'u-msg',
                    time: 3000,
                }, function () {

                });
            }, 'json');
        }

    }
</script>
</html>